package org.feng.clog.utils;

import org.feng.clog.vo.UserVo;

/**
 * 用户信息工具类
 *
 * @author feng
 */
public class UserUtil {
    private static final ThreadLocal<UserVo> USER_ENTITY_THREAD_LOCAL = new InheritableThreadLocal<>();

    private UserUtil() {
    }

    public static long currentAccountId() {
        UserVo currentUser = get();
        return currentUser == null ? -1L : get().getId();
    }

    public static UserVo get() {
        return USER_ENTITY_THREAD_LOCAL.get();
    }

    public static void set(UserVo userVO) {
        USER_ENTITY_THREAD_LOCAL.set(userVO);
    }

    public static void remove() {
        USER_ENTITY_THREAD_LOCAL.remove();
    }
}
